function init(baseInfoJson,jsonDatas,queryData){
	var basePath = $("#basePath").val();
	
	
	
	$("select").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
	});
	$("input[name='outHospitalStartDate']").val(queryData.outHospitalStartDate);
	$("input[name='outHospitalEndDate']").val(queryData.outHospitalEndDate);
	$("input[name='mrId']").val(queryData.mrId);
	$("input[name='patientName']").val(queryData.patientName);
	$("input[name='idNumber']").val(queryData.idNumber);
	$("input[name='currentPage']").val(queryData.currentPage);
	$("input[name='pageSize']").val(queryData.pageSize);
	var medicalDepts = baseInfoJson['medicalDepts'];
	$(".medicalDept").each(function(){
		var options = "";
		for(var index in medicalDepts){
			var medicalDept = medicalDepts[index];
	    	options+="<option value='"+medicalDept.uniq_code+"'>"+medicalDept.label+"</option>"
	    };
	    $(this).append(options);
	});
	if(queryData.outHospitalDeptCode){
		
		var selectOption = $("select[name='outHospitalDeptCode']").find("option[value='"+queryData.outHospitalDeptCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}
		
	}
	
	var outHospitalTypes = baseInfoJson['outHospitalTypes'];
	$(".outHospitalType").each(function(){
		var options = "";
		for(var index in outHospitalTypes){
			var outHospitalType = outHospitalTypes[index];
	    	options+="<option value='"+outHospitalType.uniq_code+"'>"+outHospitalType.label+"</option>"
	    };
	    $(this).append(options);
	});
	if(queryData.outHospitalTypeCode){
		
		var selectOption = $("select[name='outHospitalTypeCode']").find("option[value='"+queryData.outHospitalTypeCode+"']")
		if(selectOption.length > 0){
			selectOption.attr("selected",true);
		}
		
	}
	
	for(var index in jsonDatas){
		var jsonData = jsonDatas[index];
		addTr(jsonData);
    }
	
	
	if(parseInt(queryData.totalCounts) > 0){
		initPage(parseInt(queryData.totalCounts),parseInt(queryData.pageSize),parseInt(queryData.currentPage));
	}else{
		$("#totalPage").html("0");
        $("#currentPage").html("0/0");
	}
}
function queryFormSubmit(){
	$("input[name='currentPage']").val(1);
	$("#queryForm").submit();
}
function addTr(jsonData){
	var basePath = $("#basePath").val();
	var add_content=$("#template_tr").clone();
	add_content.removeAttr("id");
	add_content.removeAttr("hidden");
	add_content.find(".patient_name").html(jsonData.patient_name);
	add_content.find(".id_card").html(jsonData.id_number);
	add_content.find(".mr_id").html(jsonData.mr_id);
	add_content.find(".out_hospital_date").html(jsonData.out_hospital_date);
	add_content.find(".out_hospital_dept").html(jsonData.out_hospital_dept_name);
	add_content.find(".out_hospital_type").html(jsonData.out_hospital_type_name);
	add_content.find(".state").html("已归档");
	$("#result_table tbody").append(add_content);
}


function initPage(totalCounts,pageSize,currentPage){
	 var visiblePages = 5;
	 var totalPages =  totalCounts%pageSize==0?(totalCounts/pageSize):(parseInt(totalCounts/pageSize)+1);
	 $('#page_plus').jqPaginator({

	        totalCounts: totalCounts,
	        pageSize:pageSize,
	        visiblePages: visiblePages,
	        currentPage: currentPage,

	        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	        onPageChange: function (num,type) {

	     		if(type !='init'){
	     			$("input[name='currentPage']").val(num);
					$("#queryForm").submit();
				}
	            $("#totalPage").html(totalCounts);
	            $("#currentPage").html(num+"/"+totalPages);
	            $("#currentPageHidden").val(currentPage);
			    $("#pageSizeHidden").val(pageSize);
	        }
	    });

}
